package cn.qiyu5522.tk_ems.exception;

/**
 * @ProjectName: mybatis-plus
 * @Package: com.atguigu.common.exception
 * @ClassName: BusinessException
 * @Author: [Lucky Star]
 * @Date: 2022/10/15 16:39
 * @Version: V1.0
 **/

import cn.qiyu5522.tk_ems.result.ResponseEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 继承 RuntimeException 在 throw BusinessException 时不会提示编译异常
 */
@Data
@NoArgsConstructor
public class BusinessException extends RuntimeException{
    private Integer code;  // 错误码
    private String message;  // 错误消息

    /**
     *
     * @param message 错误消息
     */
    public BusinessException(String message){
        this.message = message;
    }

    /**
     *
     * @param code 错误码
     * @param message  错误消息
     */
    public BusinessException(Integer code, String message){
        this.code = code;
        this.message = message;
    }

    /**
     *
     * @param code  错误码
     * @param message  错误消息
     * @param cause  错误原因
     */
    public BusinessException(Integer code, String message,Throwable cause){
        super(cause);
        this.code = code;
        this.message = message;
    }

    /**
     *
     * @param responseEnum  接收异常消息枚举类型
     */
    public BusinessException(ResponseEnum responseEnum){
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    /**
     *
     * @param responseEnum  接收异常消息枚举类型
     * @param cause  错误原因
     */
    public BusinessException(ResponseEnum responseEnum,Throwable cause){
        super(cause);
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }
}
